﻿@using MealBooking.Core.Models.Orders;
@model ManagerOrder
@{
    var managerOrder = Model;
    ViewBag.HeaderTitle = "Today Order";
    Layout = "../Shared/_Layout.cshtml";
}
<!--Navbar-->
<div data-role="navbar" data-iconpos="left">
    <div class="float-left">
        <div data-role="controlgroup" data-type="horizontal" data-inset="true" data-mini="true"
            data-theme="c">
            @if (Model != null)
            {
                if (!Model.IsBooked)
                {
                    using (Html.BeginForm("BookTodayOrder", "OrderManager", FormMethod.Post))
                    {
                <button type="submit" data-icon="gear">
                    Book The Order</button>
                    }
                }
                else
                {
                <button data-icon="check" data-theme="a">
                    Booked</button>
                }
            }
            else
            {
                <button data-icon="delete" data-theme="a">
                    No Orders Yet</button>
            }
        </div>
    </div>
    <div class="float-right">
        <div data-role="controlgroup" data-type="horizontal" data-inset="true" data-mini="true"
            data-theme="c">
            <a href="@Url.Action("TodayOrders")">Customers' Orders</a> <a href="@Url.Action("HistoryOrder")">
                History Orders</a>
        </div>
    </div>
</div>
<!--Navbar End-->
@if (managerOrder != null && managerOrder.Orders.Count != 0)
{
    var mealsWithSum = managerOrder.MealsWithSum;
    <ul data-role="listview" data-inset="true" data-mini="true">
        <li data-role="list-divider">Total Price : @managerOrder.TotalPrice</li>
        <li>
            <p>
                Last Update Time : @managerOrder.LastModifyTime
            </p>
        </li>
        <li data-role="list-divider">Detail<span class="ui-li-count">@managerOrder.MealsWithSum.Sum(t => t.MealSum)</span>
        </li>
        @foreach (var mealWithSum in mealsWithSum)
        {
            var meal = mealWithSum.Meal;
            double totalPrice = meal.Price * mealWithSum.MealSum;
            <li>
                <p>
                    <strong>[@mealWithSum.MealSum Copy][@meal.Category.Name][@meal.ToString()]</strong>
                </p>
                <p>
                    Total Price : @totalPrice [@meal.Price
                    X @mealWithSum.MealSum]</p>
            </li>
        }
    </ul>
        if (!managerOrder.IsBooked)
        {
            using (Html.BeginForm("BookTodayOrder", "OrderManager", FormMethod.Post))
            {
    <ul data-role="listview" data-inset="true" data-mini="true">
        <li data-role="list-divider"></li>
        <li>
            <div data-role="filedcontain" class="ui-grid-a">
                <div class="ui-block-a">
                    <input type="submit" value="Book The Order" />
                </div>
                <div class="ui-block-b">
                    <a data-role="button" href="@Url.Action("Index")" data-theme="a">Cancel</a>
                </div>
            </div>
        </li>
    </ul>
            }
        }
}
else
{
    <ul data-role="listview" data-inset="true" data-mini="true">
        <li data-role="list-divider"></li>
        <li>No Orders yet. </li>
    </ul> 
}
